<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: xajax.add_cart.php 320 2013-09-26 19:51:08Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 320 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-26 19:51:08 +0000 (Thu, 26 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

function addCart($li_id) {
	global $price, $main, $db, $PHP_SELF;
	$check_attr = '';
	$ajax = new xajaxResponse();
	
	$arrli_id = (explode('_', $li_id));
	$id = end($arrli_id);
	
	$check_attr = $price->checkAttributes($id);
	if(!empty($check_attr))
		return $ajax->script("window.location.href = '".href_link(FILENAME_PRODUCT_INFO, 'products_id='.$id, 'SSL')."';");
	
	$_SESSION['cart']->add_cart($id, $_SESSION['cart']->get_quantity(get_uprid($id, ''))+1, '');
	
	$get_box = $db->db_query("SELECT position FROM ".TABLE_BOXES." WHERE box_name = 'shopping_cart'", true);
	
	$ajax_status = true;
	require('templates/'.CURRENT_TEMPLATE.'/source/boxes/shopping_cart.php');
	$ajax->assign('cart_content', 'innerHTML', $box_content);

	if($_SESSION['cart']->count_contents() == 1 && SCROLL_BOX_CART == 'true') {
		$j = '$(function(){var _offset = $(".box_shopping_cart").offset();var topPadding = 20;$(window).scroll(function() {if($(window).scrollTop() > _offset.top+90) {$(".box_shopping_cart").stop().animate({marginTop: $(window).scrollTop() - _offset.top + topPadding}).addClass(\'box_shopping_cart_flying\');}else{$(".box_shopping_cart").stop().animate({marginTop: 4}).removeClass(\'box_shopping_cart_flying\');};});});';
		$ajax->script($j);
	}

	$ajax->assign('box_cart_total_count', 'innerHTML', $_SESSION['cart']->count_contents());
	$ajax->script('$("#cart_content").addClass("mouse_cart")');

	$ajax->script('box_cart()');

	$ajax->call('xajax_removeLoader', $li_id, true);
	return $ajax;
}

if(!is_object($xajax))
	$xajax = new xajax();

$xajax->registerFunction("addCart");